//
//  UIImage+Compress.m
//  微看
//
//  Created by 吴明磊 on 15/8/21.
//  Copyright © 2015年 wuminglei. All rights reserved.
//

#import "UIImage+Compress.h"

@implementation UIImage (Compress)

- (UIImage *)compressImageWithWidth:(CGFloat)width {

//    if (self.size.width < width) {
//        
//        return self;
//    }
    
    CGFloat scale = self.size.height / self.size.width;
    
    CGFloat H = scale * width;
    
    CGSize size = CGSizeMake(width, H);
    
    UIGraphicsBeginImageContext(size);
    
    [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
     
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
}

@end
